package com.xiao.hao.service;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.xiao.hao.config.LocalDateTimeConfig;
import com.xiao.hao.config.UserConfig;
import com.xiao.hao.constant.HeaderConstatt;
import com.xiao.hao.constant.NumberConstants;
import com.xiao.hao.constant.UserTokenParams;
import com.xiao.hao.convertor.XhUserInfoConvertor;
import com.xiao.hao.entity.*;
import com.xiao.hao.enums.*;
import com.xiao.hao.exception.AuthException;
import com.xiao.hao.exception.BusinessException;
import com.xiao.hao.facade.XhUserInfoFacade;
import com.xiao.hao.mapper.*;
import com.xiao.hao.req.*;
import com.xiao.hao.resp.BcSelectResp;
import com.xiao.hao.resp.FileResp;
import com.xiao.hao.resp.QueryChildResp;
import com.xiao.hao.resp.QueryResp;
import com.xiao.hao.utils.*;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.beans.Transient;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @Description 用户表 服务实现层
 * @Author xiaohao
 * @Date 2025-03-01 10:58:34
 */
@Service
@Slf4j
public class XhUserInfoServiceImpl implements XhUserInfoFacade {

    @Resource
    XhUserInfoMapper mapper;

    @Resource
    RedisUtil redisUtil;

    @Resource
    XhAskAboutMapper xhAskAboutMapper;

    @Resource
    XhNutritionalPairingMapper xhNutritionalPairingMapper;

    @Resource
    XhThoughtProcessMapper xhThoughtProcessMapper;
    @Resource
    XhParamsInfoMapper xhParamsInfoMapper;
    @Resource
    XhSchemeListMapper xhSchemeListMapper;
    @Resource
    XhUserInfoFileMapper xhUserInfoFileMapper;
    @Resource
    private MinioClient minioClient;
    //普通文件桶
    @Value("${minio.bucket.files}")
    private String bucket_Files;
    @Value("${minio.local}")
    private String local;

    /**
     * 功能描述: 角色新增
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-01 10:58:34
     */
    @Transient
    @Override
    public Result insert(XhUserInfoLoginReq req) {
        Object code = redisUtil.get(NumberConstants.LOGIN_CODE_PRE + req.getMobile());
        BusinessException.isTrue(ObjectUtil.isNotEmpty(code), "验证码不存在或者已失效，请重新操作!");
        BusinessException.isTrue(req.getCode().equals(code), "验证码错误，请输入正确的验证码！");
        XhUserInfo xhUserInfo = mapper.selectOne(new LambdaQueryWrapper<XhUserInfo>().eq(XhUserInfo::getMobile, req.getMobile()));
        if (ObjectUtil.isEmpty(xhUserInfo)) {
            xhUserInfo = XhUserInfo.builder().mobile(req.getMobile()).nickName(req.getMobile()).build();
            mapper.insert(xhUserInfo);
            xhUserInfoFileMapper.insert(XhUserInfoFile.builder().userInfoId(xhUserInfo.getId()).mobile(req.getMobile())
                    .status(NumberConstants.INTEGER_ONE).nickName(req.getMobile()).build());

        }
        UserTokenParams build = UserTokenParams.builder().userName(xhUserInfo.getNickName()).userId(xhUserInfo.getId()).build();
        String encrypt =
                ParamsAesUtils.encrypt(build.getUserName() + LocalDateTimeConfig.getDateFormate(),
                        NumberConstants.AES_KEY,
                        NumberConstants.AES_IV);
        redisUtil.set(NumberConstants.TOKEN_PRE + encrypt, JSONUtil.toJsonStr(build)
                , 7200);
        return Result.succeed(encrypt);
    }

    /**
     * 功能描述: 角色修改
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-01 10:58:34
     */
    @Override
    public Result update(XhUserInfoUpdateReq req) {
        return Result.succeed(mapper.updateById(XhUserInfoConvertor.INSTANCE.reqToEntity(req)));
    }

    /**
     * 功能描述: 删除角色
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-01 10:58:34
     */
    @Override
    public Result delete(BaseId req) {
        return Result.succeed(mapper.deleteById(req.getId()));
    }

    /**
     * 功能描述: 角色分页查询
     *
     * @param req
     * @return com.xiao.hao.utils.PageResult
     * @author xiaohao
     * @date 2025-03-01 10:58:34
     */
    @Override
    public PageResult queryPage(XhUserInfoQueryPageReq req) {
        Page<XhUserInfo> page = mapper.selectPage(new Page(req.getNum(), req.getSize()), new LambdaQueryWrapper<XhUserInfo>().orderByDesc(XhUserInfo::getCreateTime));
        return PageResult.result(page.getTotal(), XhUserInfoConvertor.INSTANCE.entityListToRespList(page.getRecords()));
    }

    @Override
    public Result getLoginCode(XhUserInfoGetCodeReq req) {
        redisUtil.set(NumberConstants.LOGIN_CODE_PRE + req.getMobile(), "123123", 300);
        return Result.succeed();
    }

    @Override
    public Result outLogin() {
        BusinessException.isTrue(ObjectUtil.isNotEmpty(UserConfig.getToken()), "token不存在");
        redisUtil.del(NumberConstants.TOKEN_PRE + UserConfig.getToken());
        return Result.succeed("退出成功");
    }

    @Override
    public Result getUserInfo() {
        Object json = redisUtil.get(NumberConstants.TOKEN_PRE + UserConfig.getToken());
        AuthException.isTrue(ObjectUtil.isNotEmpty(json), "登录已过期,请重新登录！！！");
        UserTokenParams userTokenParams = JSONUtil.toBean((String) json,
                UserTokenParams.class);
        return Result.succeed(XhUserInfoConvertor.INSTANCE.entityToResp(mapper.selectById(userTokenParams.getUserId())));
    }

    @Override
    public Result getCommnEnums() {
        return Result.succeed(BcSelectResp.builder()
                .problemEnumList(ProblemEnum.getEnumRespList())
                .durationMedicationEnumList(DurationMedicationEnum.getEnumRespList())
                .eachDoseEnumList(EachDoseEnum.getEnumRespList())
                .medicationFrequencyEnumList(MedicationFrequencyEnum.getEnumRespList())
                .medicationGuidanceEnumList(MedicationGuidanceEnum.getEnumRespList())
                .usageEnumList(UsageEnum.getEnumRespList())
                .characterTypeEnumList(CharacterTypeEnum.getEnumRespList())
                .build());
    }

    @Override
    public Result gerQuery(XhAskAboutInsertReq req) {
        QueryResp queryResp = new QueryResp();
        XhAskAbout xhAskAbout = xhAskAboutMapper.selectOne(new LambdaQueryWrapper<XhAskAbout>().eq(XhAskAbout::getAge, req.getAge()).
                eq(XhAskAbout::getSex, req.getSex()).eq(XhAskAbout::getProblemCode, req.getProblemCode()));
        BusinessException.isTrue(ObjectUtil.isNotEmpty(xhAskAbout), "请按照页面提示输入问题！！！");
        List<XhThoughtProcess> xhThoughtProcesses = xhThoughtProcessMapper.selectList(new LambdaQueryWrapper<XhThoughtProcess>()
                .eq(XhThoughtProcess::getAskAboutId, xhAskAbout.getId()).orderByAsc(XhThoughtProcess::getSerialNumber));
        BusinessException.isTrue(ObjectUtil.isNotEmpty(xhThoughtProcesses), "服务器繁忙，请稍后再试！！！");

        List<QueryChildResp> resultList = Lists.newArrayList();
        QueryChildResp queryChildResp1 = new QueryChildResp();
        QueryChildResp queryChildResp2 = new QueryChildResp();
        QueryChildResp queryChildResp3 = new QueryChildResp();
        QueryChildResp queryChildResp4 = new QueryChildResp();
        resultList.add(queryChildResp1);
        resultList.add(queryChildResp2);
        resultList.add(queryChildResp3);
        resultList.add(queryChildResp4);
        queryResp.setContent(resultList);
        //思考过程
        List<XhThoughtProcess> collect1 = xhThoughtProcesses.stream().filter(x -> ProcessEnum.Process_1.getCode().equals(x.getXwType())).collect(Collectors.toList());
        List<QueryChildResp> resultList1 = Lists.newArrayList();
        collect1.forEach(c -> {
            queryChildResp1.setType(c.getTypeHead());
            queryChildResp1.setLevel(c.getLevel());
            queryChildResp1.setContent(c.getContentHead());
            resultList1.add(resultChildResp(c));
        });
        queryChildResp1.setChildren(resultList1);
        //关键点
        List<XhThoughtProcess> collect2 = xhThoughtProcesses.stream().filter(x -> ProcessEnum.Process_2.getCode().equals(x.getXwType())).collect(Collectors.toList());
        List<QueryChildResp> resultList2 = Lists.newArrayList();
        collect2.forEach(c -> {
            queryChildResp2.setType(c.getTypeHead());
            queryChildResp2.setLevel(c.getLevel());
            queryChildResp2.setContent(c.getContentHead());
            resultList2.add(resultChildRespItmes(c));
        });
        queryChildResp2.setChildren(resultList2);

        //详细报告
        List<XhThoughtProcess> collect3 = xhThoughtProcesses.stream().filter(x -> ProcessEnum.Process_3.getCode().equals(x.getXwType())).collect(Collectors.toList());
        List<QueryChildResp> resultList3 = Lists.newArrayList();
        XhThoughtProcess paragraph = collect3.stream().filter(c -> c.getType().equals("paragraph")).findFirst().get();
        queryChildResp3.setType(paragraph.getTypeHead());
        queryChildResp3.setLevel(paragraph.getLevel());
        queryChildResp3.setContent(paragraph.getContentHead());
        collect3.forEach(c -> {
            QueryChildResp queryChildResp = resultChildRespItmesTmp(c, collect3);
            if (ObjectUtil.isEmpty(queryChildResp)) {
                return;
            }
            resultList3.add(resultChildRespItmesTmp(c, collect3));
        });
        queryChildResp3.setChildren(resultList3);

        //关键引文
        XhThoughtProcess collect4 = xhThoughtProcesses.stream().filter(x -> ProcessEnum.Process_4.getCode().equals(x.getXwType())).findFirst().get();
        queryChildResp4.setType(paragraph.getTypeHead());
        queryChildResp4.setLevel(paragraph.getLevel());
        queryChildResp4.setContent(paragraph.getContentHead());
        QueryChildResp queryChildRespnNw = new QueryChildResp();
        queryChildRespnNw.setType(collect4.getType());
        queryChildRespnNw.setItems(Arrays.asList(collect4.getItems().split("\\|")));
        queryChildResp4.setChildren(Arrays.asList(queryChildRespnNw));
        return Result.succeed(queryResp);
    }

    @Override
    public Result upload(MultipartFile file) {
        String filename = file.getOriginalFilename();

        //创建一个临时文件
        File tempFile = null;
        try {
            tempFile = File.createTempFile("temp", ".temp");
            //转存临时文件
            file.transferTo(tempFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        //文件上传minio
        boolean result = addMediaFilesToMinIO(tempFile.getAbsolutePath(), bucket_Files, filename);
        if (!result) {
            BusinessException.isTrue(false, "上传文件失败");
        }
        FileResp fileResp = new FileResp();
        fileResp.setFileName(filename);
        fileResp.setHost(local);
        fileResp.setFileUrl(local + filename);

        return Result.succeed(fileResp);
    }

    @Override
    public Result gerQueryNew(XhAskAboutInsertReq req) {
        XhAskAbout xhAskAbout = xhAskAboutMapper.selectOne(new LambdaQueryWrapper<XhAskAbout>().eq(XhAskAbout::getAge, req.getAge()).
                eq(XhAskAbout::getSex, req.getSex()).eq(XhAskAbout::getProblemCode, req.getProblemCode()));
        BusinessException.isTrue(ObjectUtil.isNotEmpty(xhAskAbout), "请按照页面提示输入问题！！！");
        XhParamsInfo xhParamsInfo = xhParamsInfoMapper.selectOne(new LambdaQueryWrapper<XhParamsInfo>()
                .eq(XhParamsInfo::getAskAboutId, xhAskAbout.getId()));
        BusinessException.isTrue(ObjectUtil.isNotEmpty(xhParamsInfo), "服务器繁忙，请稍后再试！！！");

        InputStream inputStream = getClass().getResourceAsStream("/tmp.json");
        String contents = null;
        try {

            contents = IOUtils.toString(inputStream, "UTF-8");
        } catch (Exception e) {

        }
//        List<XhSchemeList> xhSchemeLists = xhSchemeListMapper.selectList(new LambdaQueryWrapper<XhSchemeList>().eq(XhSchemeList::getSchemeCode, req.getProblemCode()));
//        List<String> list = Lists.newArrayList();
//        if (xhSchemeLists.size() > 10) {
//            xhSchemeLists = xhSchemeLists.subList(0, 10);
//        }
//        xhSchemeLists.forEach(f -> {
//            list.add(f.getTitle() + f.getUrl());
//        });

        List<XhNutritionalPairing> xhNutritionalPairings = xhNutritionalPairingMapper.selectList(new LambdaQueryWrapper<XhNutritionalPairing>()
                .eq(XhNutritionalPairing::getThoughtProcessId, xhAskAbout.getId()).orderByAsc(XhNutritionalPairing::getId));
        if (xhParamsInfo.getParams1().length() > 1000) {
            xhParamsInfo.setParams1(xhParamsInfo.getParams1().substring(0, 1000) + "...");

        }
        contents = contents.replace("\"$1\"", JSONUtil.toJsonStr(Arrays.asList(xhParamsInfo.getParams1().split("\\|"))))
                .replace("\"$2\"", JSONUtil.toJsonStr(Arrays.asList(xhParamsInfo.getParams2().split("\\|"))))
                .replace("$3", xhParamsInfo.getParams3())
                .replace("$4", xhParamsInfo.getParams4())
                .replace("$5", xhParamsInfo.getParams5())
                .replace("$6", xhParamsInfo.getParams6())
                .replace("$7", xhParamsInfo.getParams7())
                .replace("$8", xhParamsInfo.getParams8())
                .replace("$9", xhParamsInfo.getParams9())
                .replace("$10", xhParamsInfo.getParams10())
                .replace("$11", xhParamsInfo.getParams11())
                .replace("$12", xhParamsInfo.getParams12())
                .replace("$13", xhParamsInfo.getParams13())
                .replace("\"$14\"", JSONUtil.toJsonStr(Arrays.asList(xhParamsInfo.getParams14().split("\\|"))))
                .replace("$15", xhParamsInfo.getParams15())
                .replace("$16", xhParamsInfo.getParams16())
                .replace("$17", xhParamsInfo.getParams17());
//                .replace("\"$18\"", JSONUtil.toJsonStr(list));
        JSONObject jsonObject = JSONUtil.parseObj(contents);
        JSONArray jsonArray = jsonObject.getJSONArray("content").getJSONObject(2).getJSONArray("children").getJSONObject(4)
                .getJSONArray("children").getJSONObject(1).getJSONArray("children").getJSONObject(0)
                .getJSONArray("children").getJSONObject(0).getJSONArray("rows");
        for (int i = 0; i < jsonArray.size(); i++) {
            XhNutritionalPairing xhNutritionalPairing = xhNutritionalPairings.get(i);
            jsonArray.getJSONObject(i).set(HeaderConstatt.HEADER_W, xhNutritionalPairing.getHeaderW());
            jsonArray.getJSONObject(i).set(HeaderConstatt.HEADER_Z, xhNutritionalPairing.getHeaderZ());
            jsonArray.getJSONObject(i).set(HeaderConstatt.HEADER_N, xhNutritionalPairing.getHeaderN());
            jsonArray.getJSONObject(i).set(HeaderConstatt.HEADER_C, xhNutritionalPairing.getHeaderC());
        }

        JSONArray jsonArray1 = jsonObject.getJSONArray("content").getJSONObject(2).getJSONArray("children").getJSONObject(4)
                .getJSONArray("children").getJSONObject(3).getJSONArray("children").getJSONObject(0).getJSONArray("rows");
        for (int i = 3; i < jsonArray1.size() + 3; i++) {
            XhNutritionalPairing xhNutritionalPairing = xhNutritionalPairings.get(i);
            jsonArray1.getJSONObject(i - 3).set(HeaderConstatt.HEADER_W, xhNutritionalPairing.getHeaderW());
            jsonArray1.getJSONObject(i - 3).set(HeaderConstatt.HEADER_Z, xhNutritionalPairing.getHeaderZ());
            jsonArray1.getJSONObject(i - 3).set(HeaderConstatt.HEADER_N, xhNutritionalPairing.getHeaderN());
            jsonArray1.getJSONObject(i - 3).set(HeaderConstatt.HEADER_S, xhNutritionalPairing.getHeaderS());
            jsonArray1.getJSONObject(i - 3).set(HeaderConstatt.HEADER_Y, xhNutritionalPairing.getHeaderY());
        }
        return Result.succeed(jsonObject);
    }

    /**
     * 将媒体文件添加到minio
     *
     * @param localFilePath 本地文件路径
     * @param bucket        桶
     * @param objectName    对象名称
     * @return boolean
     */
    public boolean addMediaFilesToMinIO(String localFilePath, String bucket, String objectName) {
        try {
            minioClient.uploadObject(
                    UploadObjectArgs.builder()
                            //上传到那个桶中
                            .bucket(bucket)
                            //指定上传MinIO中后叫什么名字
                            .object(objectName)
                            //指定本地文件路径
                            .filename(localFilePath)
                            .build());
            return true;
        } catch (Exception e) {
            log.error("上传文件到minio出错,bucket:{},objectName:{},错误原因:{}", bucket, objectName, e.getMessage(), e);
            return false;
        }

    }

    private QueryChildResp resultChildRespItmesTmp(XhThoughtProcess c, List<XhThoughtProcess> collect3) {
        QueryChildResp queryChildResp = null;
        if (c.getType().equals("paragraph") && c.getLevel().equals(3)) {
            queryChildResp = new QueryChildResp();
            queryChildResp.setType(c.getType());
            queryChildResp.setContent(c.getContent());

        }
        List<QueryChildResp> resultChildRespItmesTmp = Lists.newArrayList();
        if (c.getTypeHead().equals("heading") && c.getLevel().equals(4)) {
            queryChildResp = new QueryChildResp();
            queryChildResp.setType(c.getTypeHead());
            queryChildResp.setLevel(c.getLevel());
            queryChildResp.setContent(c.getContentHead());
            resultTmp(c, collect3, resultChildRespItmesTmp);
            queryChildResp.setChildren(resultChildRespItmesTmp);
        }
        return queryChildResp;
    }

    private void resultTmp(XhThoughtProcess c, List<XhThoughtProcess> collect3, List<QueryChildResp> resultChildRespItmesTmp) {
        QueryChildResp queryChildResp = new QueryChildResp();
        if (c.getType().equals("paragraph")) {
            queryChildResp.setType(c.getType());
            queryChildResp.setContent(c.getContent());
            resultChildRespItmesTmp.add(queryChildResp);
        }
        List<XhThoughtProcess> collect = collect3.stream().filter(f -> (f.getLevel().equals(5) || f.getLevel().equals(6)) && c.getId().equals(f.getParentId())).collect(Collectors.toList());
        collect.forEach(f -> {
            QueryChildResp queryChildResptmp = new QueryChildResp();
            queryChildResptmp.setType(f.getTypeHead());
            queryChildResptmp.setContent(f.getContentHead());
            queryChildResptmp.setLevel(f.getLevel());
            queryChildResptmp.setChildren(Arrays.asList(resultChildRespnew(f, collect3)));
            resultChildRespItmesTmp.add(queryChildResptmp);
        });

        List<XhThoughtProcess> collect1 = collect3.stream().filter(f -> String.valueOf(c.getId()).equals(f.getItems())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect1)) {
            collect1.forEach(ss -> {
                QueryChildResp queryChildResptmp = new QueryChildResp();
                queryChildResptmp.setType(ss.getType());
                queryChildResptmp.setContent(ss.getContent());
                resultChildRespItmesTmp.add(queryChildResptmp);
            });
        }
    }

    public QueryChildResp resultChildRespnew(XhThoughtProcess c, List<XhThoughtProcess> collect) {
        QueryChildResp queryChildRespTmp = new QueryChildResp();
        if (c.getType().equals("paragraph")) {
            queryChildRespTmp.setType(c.getType());
            queryChildRespTmp.setContent(c.getContent());
            return queryChildRespTmp;
        }
        if (c.getType().equals("heading")) {
            queryChildRespTmp.setType(c.getType());
            queryChildRespTmp.setLevel(c.getLevel() + 1);
            queryChildRespTmp.setContent(c.getContent());
            queryChildRespTmp.setChildren(resultChildResRow(c));
        }
        if (c.getType().equals("ordered_list")) {
            queryChildRespTmp.setType(c.getType());
            queryChildRespTmp.setItems(resultChildRespItmesNew(c, collect));
        }

        if (c.getType().equals("table")) {
            queryChildRespTmp.setType(c.getType());
            resultChildRespItmesyyfa(c, collect, queryChildRespTmp);
        }
        return queryChildRespTmp;
    }

    private void resultChildRespItmesyyfa(XhThoughtProcess c, List<XhThoughtProcess> collect, QueryChildResp queryChildRespTmp) {
        List<XhNutritionalPairing> xhNutritionalPairings = xhNutritionalPairingMapper.selectList(new LambdaQueryWrapper<XhNutritionalPairing>()
                .eq(XhNutritionalPairing::getThoughtProcessId, c.getId()).orderByAsc(XhNutritionalPairing::getId));
        List<String> list = Lists.newArrayList();
        list.add(HeaderConstatt.HEADER_DAY);
        list.add(HeaderConstatt.HEADER_Z);
        list.add(HeaderConstatt.HEADER_W);
        list.add(HeaderConstatt.HEADER_N);
        list.add(HeaderConstatt.HEADER_S);
        list.add(HeaderConstatt.HEADER_C);
        queryChildRespTmp.setHeader(list);
        List rowList = Lists.newArrayList();
        xhNutritionalPairings.forEach(f -> {
            Map map = new LinkedHashMap();
            map.put(HeaderConstatt.HEADER_DAY, f.getHeaderD());
            map.put(HeaderConstatt.HEADER_Z, f.getHeaderZ());
            map.put(HeaderConstatt.HEADER_W, f.getHeaderW());
            map.put(HeaderConstatt.HEADER_N, f.getHeaderN());
            map.put(HeaderConstatt.HEADER_S, f.getHeaderS());
            map.put(HeaderConstatt.HEADER_C, f.getHeaderC());
            rowList.add(map);
        });
        queryChildRespTmp.setRows(rowList);
    }

    private List resultChildRespItmesNew(XhThoughtProcess c, List<XhThoughtProcess> collect) {
        List<QueryChildResp> resultList = Lists.newArrayList();

        XhThoughtProcess xhThoughtProcess = collect.stream().filter(f -> c.getId().equals(f.getParentId())).findFirst().get();
        QueryChildResp queryChildRespTmpnew = new QueryChildResp();
        queryChildRespTmpnew.setContent(xhThoughtProcess.getContentHead());
        QueryChildResp queryChildRespTmpnew11 = new QueryChildResp();
        queryChildRespTmpnew11.setType(xhThoughtProcess.getType());
        queryChildRespTmpnew11.setItems(Arrays.asList(xhThoughtProcess.getItems().split("\\|")));
        queryChildRespTmpnew.setChildren(Arrays.asList(queryChildRespTmpnew11));
        QueryChildResp queryChildRespTmp = new QueryChildResp();
        queryChildRespTmp.setContent(c.getContent());
        resultList.add(queryChildRespTmpnew);
        resultList.add(queryChildRespTmp);
        return resultList;
    }

    private List<QueryChildResp> resultChildResRow(XhThoughtProcess c) {
        List<XhNutritionalPairing> xhNutritionalPairings = xhNutritionalPairingMapper.selectList(new LambdaQueryWrapper<XhNutritionalPairing>()
                .eq(XhNutritionalPairing::getThoughtProcessId, c.getId()).orderByAsc(XhNutritionalPairing::getId));
        QueryChildResp queryChildResp = new QueryChildResp();
        queryChildResp.setType("table");
        List<String> list = Lists.newArrayList();
        list.add(HeaderConstatt.HEADER_DAY);
        list.add(HeaderConstatt.HEADER_Z);
        list.add(HeaderConstatt.HEADER_W);
        list.add(HeaderConstatt.HEADER_Y);
        queryChildResp.setHeader(list);
        List rowList = Lists.newArrayList();
        xhNutritionalPairings.forEach(f -> {
            Map map = new LinkedHashMap();
            map.put(HeaderConstatt.HEADER_DAY, f.getHeaderD());
            map.put(HeaderConstatt.HEADER_Z, f.getHeaderZ());
            map.put(HeaderConstatt.HEADER_W, f.getHeaderW());
            map.put(HeaderConstatt.HEADER_Y, f.getHeaderY());
            rowList.add(map);
        });
        queryChildResp.setRows(rowList);
        return Arrays.asList(queryChildResp);
    }


    public QueryChildResp resultChildResp(XhThoughtProcess c) {
        QueryChildResp queryChildRespTmp = new QueryChildResp();
        queryChildRespTmp.setType(c.getType());
        queryChildRespTmp.setContent(c.getContent());
        return queryChildRespTmp;
    }

    public QueryChildResp resultChildRespItmes(XhThoughtProcess c) {
        QueryChildResp queryChildRespTmp = new QueryChildResp();
        queryChildRespTmp.setType(c.getType());
        queryChildRespTmp.setItems(Arrays.asList(c.getItems().split("\\|")));
        return queryChildRespTmp;
    }

}



